<?php
namespace app\admin\validate;

/**
 * 验证器
 */
use think\Validate;

class UserType extends Validate
{
    protected $rule = [
        'name'   => 'require|max:25|unique:userType',
        'module' => 'require|max:25',

    ];

    protected $message = [
        'name.require'   => '名称必须',
        'name.max'       => '名称最多不能超过25个字符',
        'name.unique'    => '名称已经存在',

        'module.require' => '模型名称必须',
        'module.max'     => '模型名称最多不能超过25个字符',
    ];

/*
// 自定义验证规则
protected function checkName($value,$rule,$data=[])
{
if(empty($data['id'])){
$where = ['name'=>$value]; //新增加时
}else{
$where = ['name'=>$value,'id'=>['neq',$data['id']]];  //修改时
}
$typename = model('user_type')->where($where)->select();
if(empty($typename)) {
return true;
}else{
return false;
}
}
 */
}
